#ifndef SERIALDATA_H
#define SERIALDATA_H

#include <QObject>
#include <QThread>
#include <QTimer>
#include <QSerialPort>
#include <QSerialPortInfo>

#include "./Crc16Class.h"
#define SERIAL_TEST 1
#define SERIAL485_ENALE_1 5


class SerialData : public QThread
{
    Q_OBJECT
public:
    explicit SerialData(QObject *parent = NULL);
    virtual ~SerialData();

    static SerialData * gestance();

    bool initSerial();

    bool initSecond();
    void setup();

    void readSerialData();
    void readCoPotency();

    void writeSerialData(QByteArray infors);
    unsigned char funCheckSum(unsigned char * i,unsigned char ln);

signals:
    void sigSendPotency(double potency);
    void sigSendStatus(int status);

public slots:
    void onReadTimeData();
    void onSerialPortReadyRead();
protected:
    void run();


private:
    int m_fd; //Linux 的思想是：将一切IO设备，都看做 文件，fd就是代表串口抽象出来的文件

    bool m_isReadData;
    QByteArray m_currentData;
    Platform::Communication::Crc16Class m_crc16class;
    bool m_isPotency;
    bool m_isRun;
    QTimer * m_dataTimer;

    QSerialPort * m_serial;
     bool m_isRecvData;
};

#endif // SERIALDATA_H
